	<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>离院管理</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="/senior_assets/css/bootstrap.min.css" rel="stylesheet">
	<link href="/senior_assets/css/style.css" rel="stylesheet">
	<link href="/senior_assets/css/font-awesome.css" rel="stylesheet">
</head>

<body>
	<div class="container-fluid">
		<div class="om-ctl-mes">
			<div class="title">
				<div class="col-xs-12"><span class="fa fa-list-ul"> 老人管理</span><b class="fa fa-caret-right"></b><i>离院管理</i></div>
			</div>
			<div class="seltemple">
				<div class="col-xs-12">
					<form class="form-inline" action="/admin_leaved" method="get">
					<?if($_SESSION['admin']['roles'] == 1 || $_SESSION['admin']['roles'] == 2){?>
					<div class="col-xs-3 mes-group"><label>部门</label><select name="department"><option value="0">请选择</option>
					<?foreach($tDDatas as $tDRow){?>
                    <option value="<?=$tDRow['num']?>" <?if($pDepartment == $tDRow['num']){echo 'selected';}?>><?=$tDRow['introduce']?></option>
                    <?}?>
					</select></div>
					<?}?>
                    <div class="col-xs-3">
                    <!--<label for="exampleInputName2">入院时间</label>
                    <div class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd" data-link-field="updated">
                    <input class="form-control" id="form-control" size="16" id="jcnow"  readonly="" placeholder="选择入院日期" type="text" name="created" value="<?=$pCreated?>" onclick="WdatePicker();">
                    </div>-->
                    <input id="updated" value="" name="updated" type="hidden"><br>
                    	
                    </div>			
					<div class="col-xs-3 mes-btn off-btn"><button id="off-btn" type="button">新增老人离院</button><button id="search" type="button">搜索</button></div>
				</form>
				</div>
			</div>
			<div  class="mes-conttent col-xs-12">
				<table class="table off-table">
	              <thead>
	             	<tr>
			        <th>编号</th>
			        <th>老人姓名</th>
			        <th>部门</th>
			        <th>入院时间</th>
			        <th>出院时间</th>
			        <th>是否结算</th>
			        <th>离院原因</th>
		            </tr>
	              </thead>
	             <tbody>
		           <?foreach($tDatas as $tRow){?>
		           <tr>
		           	 <td><?=$tRow['id']?></td>
			         <td><span><?=$tRow['name']?></span><small class="hiddendiv"></small></td>
			         <td><?=$tRow['department']?></td>
			         <td><?=date('Y-m-d',$tRow['created'])?></td>
			         <td><?=date('Y-m-d',$tRow['leavetime'])?></td>
			         <td><?=$tRow['created'] == 1?'已结算':'未结算'?></td>
			         <td><span class="say"><?=$tRow['leaved_reason']?></span><small class="hiddendiv"></small></td>
		           </tr>
		           <?}?>
	            </tbody>
              </table>
			</div>
		</div>
    </div>
        <script type="text/javascript" src="/senior_assets/js/jquery.min.js"></script>
    <script type="text/javascript" src="/senior_assets/js/jq.js"></script>
    <script type="text/javascript" src="/plugins/datepicker/WdatePicker.js" charset="UTF-8"></script>
    <script type="text/javascript">
    </script>
    <script>
    $(function(){
	var offalert="<div class='off-alert'></div>",
	    html = "<div class='mark'></div>"
	           +"<div class='off-alert'>"
				  +"<h3>新增老人离院<span  class='close1'>×</span></h3>"
				  +"<form method='post' class='addTrain'><div class='sle'><label>部门</label><select name='department' class='department'><option value='0'>请选择</option><?foreach($tDDatas as $tDRow){?><option value='<?=$tDRow["num"]?>'><?=$tDRow["introduce"]?></option><?}?></select><label class='supportworker_name'>姓名</label><select name='name' class='supportworker'><option>请选择</option></select><label>离院时间</label><input type='text' readonly='readonly' placeholder='2017-09-12' onclick='WdatePicker()'></select></div>"
				  +"<div class='col-xs-12'><div class='col-xs-4'>离院原因</div><div class='col-xs-8'><textarea name='leaved_reason'></textarea></div></div></form>"
				  +"<div class='btns'><button type='button' onclick='addUser()'>保存</button><button class='close1'>取消</button></div>"
          +"</div>";
	    $("body").prepend($(html))
	    $(".mark").css("height",$(document).height()+"px")    
	   	$(".mark").addClass('hidden')  
	   	$(".off-alert").addClass('hidden')
	      $("#off-btn").click(function(){
	           $('.mark').show()
	           $('.off-alert').show()
	           $(".off-alert").removeClass('hidden')
	           $(".mark").removeClass('hidden')
	            $('select[name="department"]').change(function(){
                var department_id = $(this).val();
                $.post('/admin_leaved',{department_id:department_id},function(obj){
                    $('select[name="name"]').remove();
                    if(obj.status == 1){
                        var data = obj.data;
                        var html = (
                            '<select name="name">'
                        );
                        $.each(data,function(key,row){
                            html += '<option value="'+row.id+'">'+row.name+'</option>';
                        }); 
                        html += '</select>';
                        html += '<input type="hidden" name="tId" value="" class="tId"/>'
                        $('.supportworker_name').after(html);
                    }
                });
            });
	       
	     })
	    $(".close1").click(function(){
	           $('.mark').hide()
	           $('.off-alert').hide()
	           $(".off-alert").addClass('hidden')
	           $(".mark").addClass('hidden')
	     })
    });
    </script>
    <script>
	$('#search').click(function(){
	$('form').submit();
	});
	function addUser(){
    var data = $('.addTrain').serialize();
    $.post('/admin_leaved/add',data,function(obj){alert(obj.msg);location.href="/admin_leaved";});
	}
	</script>
</body>
</html>
